package com.ray.pojo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Repository;

@Repository("studentByAnnotation")
// @Component("annotatedStudent") 推荐pojo用Repository，更具有可读性
public class Student
{
    private String name;
    private int age;

    /**
     * 引用类型
     *
     * @Autowired:spring框架提供的，给引用类型赋值的，使用自动注入原理 支持byName, byType, 默认是byType
     * 位置：1) 在属性定义的上面，无需set方法，推荐使用
     * 2) 在set方法的上面
     */
    // 默认使用byType

    // 自动装配，默认是byType
    @Autowired
    // 如果需要byName自动装配，则加上@Qualifier注解
    @Qualifier("schoolByAnnotation")
    private School school;

    @Value("jack")
    public void setName(String name)
    {
        System.out.println("setName == " + name);
        this.name = name;
    }

    @Value("16")
    public void setAge(int age)
    {
        System.out.println("setAge == " + age);
        this.age = age;
    }

    public School getSchool()
    {
        return school;
    }

    public void setSchool(School school)
    {
        System.out.println("setSchool == " + school);
        this.school = school;
    }

    @Override
    public String toString()
    {
        return "Student{" + "name='" + name + '\'' + ", age=" + age + ", school=" + school + '}';
    }
}
